package com.wu.Backstage.service.impl;

import cn.hutool.core.util.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wu.Backstage.entity.UserAccount;
import com.wu.Backstage.mapper.UserMapper;
import com.wu.Backstage.service.UserService;
import com.wu.Backstage.tool.PageHelperUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Date;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

@Service(value = "userService")
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public List<UserAccount> getAllUser() {
        return userMapper.getAllUser();
    }

    @Override
    public UserAccount getAllUserByName(String name) {
        return userMapper.getAllUserByName(name);
    }

    @Override
    public UserAccount getAllUserById(Integer id)
    {
        return userMapper.getAllUserByID(id);
    }

    @Override
    public UserAccount getAllUserEmail(String email)
    {
        return userMapper.getAllUserByEmail(email);
    }

    @Override
    public UserAccount loginPage(String email, String password) {
        return userMapper.loginPage(email,password);
    }

    @Override
    public int AddUser(String email, String password, String name, Date date, Time time,Integer statuscode,String sex,Integer age,String dsc)
    {
        return userMapper.logounPage(email,password,name,date,time,statuscode,age,sex,dsc);
    }

    @Override
    public int upadteStat(String email)
    {
        return userMapper.upadteStat(email);
    }

    @Override
    public int DataleUsre(Integer id)
    {
        return userMapper.DataleUsre(id);
    }

    @Override
    public int UpdateUsre(String email,String name,String password,Integer statuscode,Integer age,String sex,String dsc,Integer id)
    {
        return userMapper.UpdateUsre(email,name,password,statuscode,age,sex,dsc,id);
    }

    @Override
    public ArrayList<HashMap<String,Object>> findCommodityEntityPoSp(Integer sta, Integer st){
        return userMapper.findCommodityEntityPoSp(sta,st);
    }

    @Override
    public ArrayList<HashMap<String,Object>> findshoppingCard(String email)
    {
        return userMapper.findshoppingCard(email);
    }


    @Override
    public int findCount(String email){
        return userMapper.findCount(email);
    }



    @Override
    public ArrayList<HashMap<String,Object>> findOrder(String email,Integer page,Integer num){
        return userMapper.findOrder(email,page,num);
    }

    @Override
    public  int UserUpdateUsre(String name,String password,Integer age,String sex,String dsc,Integer id,String img)
    {
        return userMapper.UserUpdateUsre(name,password,age,sex,dsc,id,img);
    }

    @Override
    public  int ComCount(Integer id){
        return userMapper.ComCount(id);
    }


    @Override
    public ArrayList<HashMap<String,Object>> findevaluated (String dityid){
        return userMapper.findevaluated(dityid);
    }

    @Override
    public ArrayList<HashMap<String,Object>> findCommCount(){
        return userMapper.findCommCount();
    }


    @Override
    public  ArrayList<HashMap<String,Object>> finSearchProducts (String name){
        return userMapper.finSearchProducts(name);
    }


    @Override
    public PageHelperUtil<UserAccount> getUserAccountPage(Integer page, Integer pageSize){

        //起始页和每页要显示的数据
        PageHelper.startPage(page,pageSize);
        //查询所有信息
        List<UserAccount>  list = userMapper.getAllUser();
        PageInfo<UserAccount> pageInfo = new PageInfo<>(list);

        PageHelperUtil<UserAccount> result = new PageHelperUtil<>();
       //结果集封装到当前页
        result.setPage(page);
        //每页数
        result.setPageSize(pageInfo.getPageSize());
        //总页数
        result.setPageTotal(pageInfo.getPages());
        //总条数
        result.setTotal(pageInfo.getTotal());
        //结果集
        result.setList(pageInfo.getList());

        return result;

    }




}
